import {_decorator, Component, Node, Sprite, Label} from 'cc';
import {AudioManager} from "db://assets/scripts/common/AudioManager";
import {PriorityEnum} from "db://assets/scripts/game/PriorityEnum";
import {UIManager} from "db://assets/scripts/common/UIManager";
import {EventManager} from "db://assets/scripts/common/EventManager";
import {PlayerDataManager} from "db://assets/scripts/common/PlayerDataManager";
import {AudioPaths} from "db://assets/scripts/common/AudioPaths";
import {EventType} from "db://assets/scripts/common/EventType";

const {ccclass, property} = _decorator;

@ccclass('HomeController')
export class HomeController extends Component {
    /**
     * 等级图标
     */
    @property(Sprite)
    public levelNameSprite: Sprite;
    /**
     * 等级
     */
    @property(Label)
    public levelLabel: Label;

    /**
     * 回调
     */
    private callback: Function;

    public show(callback?: Function) {
        this.callback = callback;
        //已经解锁的最高层级
        this.levelLabel.string = `${PlayerDataManager.getInstance().getPlayer().heightFloor}层`;
    }

    /**
     * 显示设置界面
     */
    onSetting() {
        // 播放声音
        AudioManager.getInstance().playSound(AudioPaths.clickSound);
        // 显示设置界面
        UIManager.getInstance().showDialog("setting/settingPanel", null, null, PriorityEnum.DIALOG);
    }

    /**
     * 开始游戏
     */
    onStart() {
        // 播放声音
        AudioManager.getInstance().playSound(AudioPaths.homePanelClickSound);
        // 关闭主界面
        UIManager.getInstance().hideDialog("home/homePanel");
        // 分发事件
        EventManager.dispatchEvent(EventType.ON_GAME_INIT);
    }
}